/**
 * Definition for singly-linked list. */
struct ListNode {
      int val;
      ListNode *next;
      ListNode() : val(0), next(nullptr) {}
      ListNode(int x) : val(x), next(nullptr) {}
      ListNode(int x, ListNode *next) : val(x), next(next) {}
  };

class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
        ListNode* slow = head;
        if (!slow || !slow->next)return head;
        ListNode* fast = slow->next;

        while (fast)
        {
            if (fast->val == slow->val)
            {
                ListNode* del = fast;
                fast = fast->next;

                slow->next = fast;
                delete del;
            }
            else
            {
                slow = slow->next;
                fast = fast->next;
            }
        }
        return head;
    }
};